
#include <stdio.h>
#include <stdlib.h>

#include "expression.h"
#include "program.h"
#include "symtab.h"

struct program* create_program()
{
    struct program* res = (struct program*)malloc(sizeof(struct program));
    res->global = create_symbol_table();
    res->exprc = 0;
    res->execlist = (struct expression**)malloc(PROGRAM_LENGTH * sizeof(struct expression*));
}

void destroy_program(struct program* prog)
{
    destroy_symbol_table(prog->global);
    free(prog->execlist);
    free(prog);
}

void append_expression(struct program* prog, struct expression* expr)
{
    prog->execlist[prog->exprc] = expr;
    ++prog->exprc;
}

int execute_program(struct program* prog)
{
    for(int i = 0; i < prog->exprc; ++i) {
        double result = evaluate(prog->execlist[i], prog->global);
        printf("%lf\n", result);
    }
    return 0;
}

